<?php

namespace App\Http\Controllers\Logic;

use App\Http\Controllers\Controller;
use App\Model\OASupplier;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use App\Libs\UploadFile;
/**
 * Class DeptLogic
 * @package App\Http\Controllers\Logic
 * @desc 部门操作逻辑
 */
class SupplierLogic extends Controller
{

    //注册
    public function registerUser($input)
    {
        DB::beginTransaction();
        try {
            $supplier = new OASupplier();
            $isExists = OASupplier::query()->where('phone',$input['phone'])->exists();
            if($isExists) throw new \Exception('手机号:'.$input['phone'].'已存在');
            $password1 = md5($input['password']);
            $password2 = md5($input['repeatPassword']);
            if($password1 != $password2) throw new \Exception('两次密码不一致');
            $data = [
                'company'       => $input['company'],
                'username'      => $input['username'],
                'address'       => $input['address'],
                'email'         => $input['email'],
                'account'       => $input['account'],
                'phone'         => $input['phone'],
                'password'      => $password1,
                'repeatPassword'=> $password2,
                'register_time' => date('Y-m-d H:i:s')
            ];
            $supplier->insertGetId($data);
            DB::commit();
            return true;
        }catch(\Exception $e){
            DB::rollBack();
            throw new \Exception($e->getMessage());
        }

    }
}
